package com.adee.nowcoder.huawei;

public class T023_HJ24_2 {
    public static void main(String[] args) {
        // int[] arr = {1,3,4,4,5,5,6,6,8,10};
        int[] arr = {0,0};
        int a = 0;
        int idx = binSearch(arr,0,arr.length-1, a);
        System.out.println(idx + " " + arr[idx]);

    }

    // 返回arr从左到右第一个大于等于a的元素下标，若都小于a，返回-1
    public static int binSearch(int[] arr, int begin, int end, int a) {
        if(a <= arr[begin]) return begin;
        if(a > arr[end]) return -1;
        int mid = 0;
        while(begin <= end) {
            mid = (begin+end)/2;
            if(a < arr[mid]) {
                end = mid-1;
            }else if(a > arr[mid]) {
                begin = mid+1;
            }else {
                return mid;
            }
        }
        if(arr[mid] < a) return mid + 1;
        else return mid;
    }

}
